import { Database } from "./database.js";
import mysql from "mysql2";
/**
 * MySql 数据库操作子类型
 * @class MySql
 * @extends Database
 */
export class MySql extends Database {
  static engine = "mysql";

  constructor(config) {
    super();
    this.db = mysql.createPool(config);
  }

  async run(sql, params) {
    return new Promise((resolve, reject) => {
      this.db.execute(sql, params, (err, results) => {
        if (err) return reject(err);
        resolve(results);
      });
    });
  }

  async end() {
    this.db.end();
  }
}
